/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.flexengine.script;

import com.flexengine.config.ConfigurationWindow;
import com.flexengine.engine.FlexEngine;
import com.flexengine.logger.Logger;
import com.flexengine.time.TimeManager;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * @author Luann R. Athayde
 * @version 1.0
 * @since 1.0
 */
public class FlexInterpreter {
    
    public static void init(String ... args) {
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine jsEngine = factory.getEngineByName("JavaScript");
        
        Logger.setDebugLevel(Logger.DEBUG_ALL);
        jsEngine.put("timeManager", TimeManager.getInstance());
        jsEngine.put("engine", FlexEngine.getInstance());
        jsEngine.put("setup", ConfigurationWindow.getInstance());
        
        String code = ""
                + "setup.setVisible(true);"
                + "engine.start();";
        
        try {
            jsEngine.eval(code);
        } catch(ScriptException e) {
            System.err.println(e);
        }
    }
    
}
